<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Modules_News_Models_Mysql_ArticleRelate extends Modules_News_Models_ArticleRelate
{	
	protected $_table = 'news_article_relate_assoc';
	
	public function getArticles($articleId)
	{
		$sql = 'SELECT a.* FROM ' . $this->_conn->_tablePrefix . 'news_article AS a
				INNER JOIN ' . $this->_conn->_tablePrefix . $this->_table . ' AS ars
					ON a.article_id = ars.relate_article_id 
				WHERE a.status = "active" AND ars.article_id = "' . $this->_conn->escape($articleId) . '"';
		$sql .= ' ORDER BY a.created_date DESC, a.article_id DESC';

		$rs = $this->_conn->query($sql);
		$rows = array();
		while ($row = $this->_conn->fetchAll($rs)) {
			$rows[] = $this->format($row);
		}
		/**
		 * Free result 
		 */
		$this->_conn->freeResult($rs);
		return $rows;
	}
}